<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/element.css">
<style>
    body,html{
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
    }
</style>
</head>
<body>
<@titlelist pageNum=pageNum pageSize=pageSize keyword=keyword>
<div id="app">
    <#include "/include/daohang.html">

    <div align="center">
        <div style="width: 500px">
            <div style="margin-top: 15px;">
                <el-autocomplete
                        style="width: 500px"
                        class="inline-input"
                        v-model="keyword"
                        :fetch-suggestions="querySearch"
                        placeholder="请输入内容"
                        @select="handleSelectKeyWord"
                >
                    <el-button slot="append" @click="searchnote" id="search-btn" icon="el-icon-search"></el-button>
                </el-autocomplete>
            </div>
        </div>
        <br>

        <#if keyword?length gt 0>
            <div align="left" style="padding-left: 15%">
                <span>以下是包含${keyword}的所有结果</span>
            </div>
        </#if>

        <el-divider></el-divider>

        <div style="padding: 20px">
            <template>
                <el-table
                        :data="tableData"
                        style="width: 90%"
                        height="600">
                    <el-table-column
                            label="序号"
                            width="150px">
                        <template slot-scope="scope">{{ scope.$index+1 }}</template>
                    </el-table-column>
                    <el-table-column
                            label="标题"
                            width="450px">
                        <template slot-scope="scope" ><a @click="locationppreview(scope.row)">{{ scope.row.title }}</a></template>
                    </el-table-column>
                    <el-table-column
                            prop="tag"
                            label="标签"
                            width="100px">
                    </el-table-column>
                    <el-table-column
                            prop="viewnum"
                            label="点击次数"
                            width="150px">
                    </el-table-column>
                    <el-table-column
                            prop="createTime"
                            label="创建时间"
                            width="250px">
                    </el-table-column>
                </el-table>
                <el-pagination
                        background
                        @current-change="handleCurrentChange"
                        layout="total,prev, pager, next"
                        :total="total"
                        :current-page="pageNum">
                </el-pagination>
            </template>
        </div>
    </div>
</div>
<#include "/include/commonjs.html">
<script>

    var Main = {
        extends: global,
        data() {
            return {
                restaurants: [],
                state: '',
                activeIndex: '1',
                activeIndex2: '1',
                total:${result.total},
                tableData: ${result.records},
                keyword: '${keyword}',
                pageNum: ${pageNum},
                pageSize: ${pageSize}
            }
        },
        created(){

        },
        methods: {
            querySearch(queryString, cb) {
                console.log('调用了'+queryString)
                api.GET('/no/note/keyword',{'keyword':queryString},(result)=>{
                    if(result.code===0){
                        var restaurants=result.data;
                        // 调用 callback 返回建议列表的数据
                        cb(restaurants);
                    }
                });
            },
            handleSelectKeyWord(item) {
                this.searchnote();
            },
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
            },
            handleCurrentChange(val) {
                location.href="?pageNum="+val+"&pageSize="+this.pageSize+"&keyword="+this.keyword;
            },
            locationppreview(val){
                console.log(JSON.stringify(val))
                window.open(val.contentUrl);
               // window.open('/page/contentinfo.html?obj='+id)
            },
            searchnote(){
                this.pageNum=1;
                location.href="?pageNum="+this.pageNum+"&pageSize="+this.pageSize+"&keyword="+this.keyword;
            },
            loadAll() {
                return [
                    { "value": "三全鲜食（北新泾店）", "address": "长宁区新渔路144号" },
                    { "value": "Hot honey 首尔炸鸡（仙霞路）", "address": "上海市长宁区淞虹路661号" },
                ];
            },
        },
        mounted() {
            this.restaurants = this.loadAll();
        }
    }
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')

    function keyDown() {
        var keycode = event.keyCode;
        var realkey = String.fromCharCode(event.keyCode);
        if(keycode==13){
            $("#search-btn").click();
        }
        // alert("按键码: " + keycode + " 字符: "+ realkey);

    }
    document.onkeydown = keyDown;
</script>
</@titlelist>
</body>
</html>